﻿using Slex;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Test.Scenes {
    public partial class CometNight : UserControl {
        public CometNight() {
            InitializeComponent();
            InitialUserCom();
        }

        private void InitialUserCom() {
            this.Loaded += CometNight_Loaded;
        }
        Random ran = new Random();
        void CometNight_Loaded(object sender, RoutedEventArgs e) {
            var x = new Ellipse();
            x.Width = x.Height = 15;
            x.RenderTransform = new TranslateTransform();
            x.Effect = new System.Windows.Media.Effects.BlurEffect();
            x.Fill = Brushs.Snow.ToBrush();
            var dm1 = new DoubleAnimation();
            Storyboard.SetTargetProperty(dm1, new PropertyPath("Opacity"));
            Storyboard.SetTarget(dm1, x);
            var dm2 = new DoubleAnimation();
            Storyboard.SetTargetProperty(dm2, new PropertyPath("(Ellipse.RenderTransform).(TranslateTransform.Y)"));
            Storyboard.SetTarget(dm2, x);
            var dm3 = new DoubleAnimation();
            Storyboard.SetTargetProperty(dm3, new PropertyPath("(Ellipse.RenderTransform).(TranslateTransform.X)"));
            Storyboard.SetTarget(dm3, x);
            var dm4 = new DoubleAnimation();
            Storyboard.SetTargetProperty(dm4, new PropertyPath("Width"));
            Storyboard.SetTarget(dm4, x);
            var dm5 = new DoubleAnimation();
            Storyboard.SetTargetProperty(dm5, new PropertyPath("Height"));
            Storyboard.SetTarget(dm5, x);
            var dm6 = new ColorAnimation();
            Storyboard.SetTargetProperty(dm6, new PropertyPath("(Ellipse.Fill).(SolidColorBrush.Color)"));
            Storyboard.SetTarget(dm6, x);
            //
            var time = 8000;
            var time2 = TimeSpan.FromMilliseconds(time);
            dm4.To = 10;
            dm5.To = 10;
            dm4.Duration = time2;
            dm5.Duration = time2;
            dm2.From = ran.Next(50);
            dm2.To = 480;
            dm2.EasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseIn };
            dm3.From = 50;
            dm3.To = this.LayoutRoot.ActualWidth - 50;
            dm1.From = .9 + ran.NextDouble();
            dm1.To = .1;
            dm6.To = Colors.Red;
            dm6.Duration = dm2.Duration = dm3.Duration = dm1.Duration = time2;
            //
            sb.Children.Add(dm1);
            sb.Children.Add(dm2);
            sb.Children.Add(dm3);
            sb.Children.Add(dm4);
            sb.Children.Add(dm5);
            sb.Children.Add(dm6);
            //
            x.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            x.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.LayoutRoot.Children.Add(x);
            sb.RepeatBehavior = new RepeatBehavior(10);
            sb.Begin();
        }
    }
}
